<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>苹果后台</title>
<script type="text/javascript" src="${path}/js/back/jquery.min.js"></script>
<script type="text/javascript"
	src="${path}/js/back/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${path}/js/back/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="${path}/js/back/datagrid-detailview.js"></script>
<link rel="stylesheet" href="${path}/css/back/themes/default/easyui.css"
	type="text/css" />
<link rel="stylesheet" href="${path}/css/back/themes/icon.css"
	type="text/css" />
<link rel="stylesheet" type="text/css"
	href="${path}/css/back/demo.css">
	 <style type="text/css"> 
        #fm 
        { 
            margin: 0; 
            padding: 10px 30px; 
        } 
        .ftitle 
        { 
            font-size: 14px; 
            font-weight: bold; 
            padding: 5px 0; 
            margin-bottom: 10px; 
            border-bottom: 1px solid #ccc; 
        } 
        .fitem 
        { 
            margin-bottom: 5px; 
        } 
        .fitem label 
        { 
            display: inline-block; 
            width: 80px; 
        } 
    </style> 
</head>
<body>
<script type="text/javascript">
		var data = ${data};
 $(function(){
	    	$('#dg').datagrid({
	    		/* url:"${path}/manager/toUserEditInit", */
	    		fitColumns:true,//列自适应宽度，不能和冻结列同时设置为true
	    	        striped:true,//斑马线效果
	    	        idField:'goodsID',//主键列
	    	        rownumbers:true,//显示行号
	    	        singleSelect:true,//是否单选
	    	        pagination:true,//显示分页栏
	    	        pageList:[10,20,50,100],//每页行数选择列表
	    	        pageSize:10,//出事每页行数
	    	        remoteSort:false,//是否服务器端排序，设成false，才能客户端排序
	    	        sortName:'goodsID',//设置排序列
	    	        sortOrder:'desc',//排序方式
	    	        rownumbers:true,
	    	    columns:[[
	    	        {field:'goodsID',title:'商品编号',width:100},
	    	        {field:'goodsName',title:'商品名',width:100},
	    	        {field:'goodsColor',title:'商品颜色',width:100},
	    	        {field:'goodsImgForShow',title:'商品展示图片',width:100},
	    	        {field:'goodsInfo',title:'商品信息',width:150},
	    	        {field:'goodsImg',title:'商品图片',width:150},
	    	        {field:'iPadConn',title:'ipad连接方式',width:150},
	    	        {field:'macDisc',title:'mac硬盘',width:150},
	    	        {field:'price',title:'价格',width:150},
	    	        {field:'num',title:'剩余数量',width:150}
	    	    ]],
	    	     toolbar:[{
	    	    	    text:'新增',
	    	    	    iconCls: 'icon-add',
	    	    	    handler: function(){
	    	    	    	add();
	    	    	    }
	    	    	    },'-',{
	    	    	    	text:'修改',
	        	    	    iconCls: 'icon-edit',
	        	    	    handler: function(){
	        	    	    	update();
	        	    	    }
	    	    	    },'-',{
	    	    	    	text:'删除',
	    	    	    	iconCls: 'icon-remove',
	        	    	    handler: function(){
	        	    	    	destroyUser();
	        	    	    }
	    	    	    }]
	    	});
	    });
 function add() {
	 $("#dlg").dialog("open").dialog('setTitle', '新增商品');
	 $("#fm").form("clear");
}
 function save() {
     $("#fm").form("submit", {
         url: "${path}/BackGoods/AddGoods",
         onsubmit: function () {
             return $(this).form("validate");
         },
         success: function (result) {
             if (result) {
                 $.messager.alert("提示信息", "操作成功");
                 $("#dlg").dialog("close");
                 $("#dg").datagrid("load");
             }else {
                 $.messager.alert("提示信息", "操作失败");
             }
         }
     });
 }
 function saveuser() {
	 var row = $('#dg').datagrid('getSelected');
	 $("#fmm").form("submit", {
         url: url = "BackGoods/UpdateGoods?goodsID=" + row.goodsID,
         onsubmit: function () {
             return $(this).form("validate");
         },
         success: function (result) {
             if (result) {
                 $.messager.alert("提示信息", "修改成功");
                 $("#dllg").dialog("close");
                 $("#dg").datagrid("load");
             }else {
                 $.messager.alert("提示信息", "操作失败");
             }
         }
     });
}
function update(){
	var row = $('#dg').datagrid('getSelected');
	if(row){
		$("#dllg").dialog("open").dialog('setTitle', '更新商品');
		$("#fmm").form("clear");
		$("#fmm").form("load", row);
         url = "manager/UpdateUserUI?uID=" + row.uID;
	}
}
function destroyUser() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $.messager.confirm('Confirm', '您确认删除吗?', function (r) {
            if (r) {
                $.post("BackGoods/DeleteGoods?goodsID=" + row.goodsID, function (json) {
                		 $.messager.alert("提示信息", "删除成功");
                		 $("#dlg").dialog("close");
                		 $("#dg").datagrid("load");
                });
            }
        });
    }else{
   	 $.messager.alert("提示信息", "请选择要删除的数据");
    }
}  
	</script>
<!-- data-options="data:data" -->
	<table id="dg" class="easyui-datagrid" title="商品管理"
		style="width: 700px; height: 365px" toolbar="#toolbar"
		data-options="data:data"
		pagination="true" fitColumns="true" singleSelect="true">
	</table>

	<div id="dlg" class="easyui-dialog" style="width: 500px; height: 300px; padding: 10px 20px;" closed="true" buttons="#dlg-buttons"> 
		       <form id="fm" method="post" enctype="multipart/form-data">
		       <div class="fitem"> 
		           商品名<input id="goodsName" name="goodsName" class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		            商品颜色 <input id="goodsColor" name="goodsColor"  class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		           商品展示图片	<input id="goodsImgForShow" name="goodsImgForShow" class="easyui-vlidatebox"/> 
		       </div> 
		           <div class="fitem"> 
		           商品配置信息	<input id="goodsInfo" name="goodsInfo" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		           商品图片	<input type="file" id="goodsImg" name="goodsImg" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		   ipad连接方式	<input id="iPadConn" name="iPadConn" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		           mac硬盘大小	<input id="macDisc" name="macDisc" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		          价格	<input id="price" name="price" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		          剩余数量	<input id="num" name="num" class="easyui-vlidatebox"/> 
		       </div> 
		       </form> 
		</div>
		<div id="dlg-buttons"> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()" iconcls="icon-save">保存</a> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')"
	            iconcls="icon-cancel">取消</a> 
	</div>
	<div id="dllg" class="easyui-dialog" style="width: 500px; height: 300px; padding: 10px 20px;" closed="true" buttons="#dlg-buttons"> 
		       <form id="fmm" method="post"  enctype="multipart/form-data">
		          <div class="fitem"> 
		           商品名<input id="goodsName" name="goodsName" class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		            商品颜色 <input id="goodsColor" name="goodsColor"  class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		           商品展示图片	<input id="goodsImgForShow" name="goodsImgForShow" class="easyui-vlidatebox"/> 
		       </div> 
		           <div class="fitem"> 
		           商品配置信息	<input id="goodsInfo" name="goodsInfo" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		           商品图片	<input type="file" id="goodsImg" name="goodsImg" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		   ipad连接方式	<input id="iPadConn" name="iPadConn" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		   mac硬盘大小	<input id="macDisc" name="macDisc" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		          价格	<input id="price" name="price" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		          剩余数量	<input id="num" name="num" class="easyui-vlidatebox"/> 
		       </div> 
		       <input type="hidden" name="goodsID" id="goodsID" /> 
		       </form> 
		</div>
	<div id="dlg-buttons"> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="saveuser()" iconcls="icon-save">保存</a> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dllg').dialog('close')"
	            iconcls="icon-cancel">取消</a> 
	</div>
</body>
</html>